<?php
$parentCaption = 'Merchants';
$caption = 'Merchant List';
$this->pageTitle = $caption;

$this->breadcrumbs = array(
	$parentCaption
);

//list admin
$admin_list = array();
$connection = Yii::app()->db;
$command = $connection->createCommand('SELECT id, name FROM tbl_sys_admin_account WHERE status=0 ORDER BY name');
$admins = $command->queryAll(true);
$connection->active = false;
foreach ($admins as $sys) {
	$admin_list[(int)$sys['id']] = $sys['name'];
}

$all_lbl = BUtils::T('all_op_lbl');
?>
<div class="page-header position-relative">
	<h1>
		<?php echo $parentCaption; ?>
		<small>
			<i class="icon-double-angle-right"></i>
			<?php echo $caption; ?>
		</small>
	</h1>
</div><!--/.page-header-->

<div class="row-fluid">
	<div class="row-fluid">
		<div class="span12">
			<div class="widget-box transparent">
				<div class="widget-header">
					<h3 class="lighter blue"><?php echo $caption; ?></h3>
					<div class="widget-toolbar">
						<a href="<?php echo Yii::app()->createUrl('/tools/merchant/form'); ?>">
							<i class="icon-edit blue"></i>
							<span>Create New Merchant</span>
						</a>
					</div>
				</div>
				<div class="widget-body">
					<div class="widget-body-inner">
					<div class="widget-main no-padding">
						<div class="dataTables_wrapper">
							<div class="row-fluid no-border">
								<div class="span12">
									<div class="dataTables_paginate" style="padding-right:8px;">
<?php
echo CHtml::form(Yii::app()->createUrl('/tools/merchant'), 'post', array('id'=>'search_form', 'style'=>'margin-bottom:8px;'));
echo CHtml::textField('q', '', array('style'=>'width:40%', 'placeholder'=>'No., name, address or neighborhoods?'));
echo CHtml::dropDownList('id_admin', '', $admin_list, array('empty'=>'All Editors', 'style'=>'width:auto;'));
echo CHtml::dropDownList('sort', 'time', array('time'=>'Sort by time','name'=>'Sort by name'), array('style'=>'width:auto;'));
echo CHtml::ajaxSubmitButton(BUtils::T('search_btn'), null, array('beforeSend'=>'beforeSend', 'success'=>'success'), array('class'=>'btn btn-blue'));
echo CHtml::endForm();
?>
									</div>
								</div>
							</div>
						</div>
						<div class="mobile">
							<div id="loading-bar" style="text-align:center; margin:20px 0;">
								<img src="<?php echo Yii::app()->baseUrl; ?>/img/ajax-loaders/ajax-loader-4.gif" />
							</div>
							<div id="merchant-list"></div>
						</div>
					</div>
					</div>
				</div>
			</div><!-- end of widget-box -->
		</div>
	</div>
</div>
<script type="text/javascript">
$(function() {
	$.ajax({
		'beforeSend':beforeSend, 'success':success,
		'type':'POST', 'url':location.href, 'data':$('#search_form').serialize()
	});
	$('#search_form select').change(function(){
		$.ajax({
			'beforeSend':beforeSend, 'success':success,
			'type':'POST', 'url':location.href, 'data':$('#search_form').serialize()
		});
	});
});
function beforeSend() {
	$("#loading-bar").show();
	$("#merchant-list").html('');
}
function success(html) {
	$("#loading-bar").hide();
	$("#merchant-list").html(html);
}
</script>